﻿

<CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@IconType.Home.ToIconString()" Title="主要信息" Class="@Class" Collapable>
    <MRow>
        <MCol Cols="12" Md="6" Lg="4">
            <CnGalWebSite.Components.Images.UploadButton ShowCropper @bind-ImagePath="@Model.MainPicture" Type="ImageAspectType._16_9" Text="上传主图" Class="mb-4"/>
         </MCol>
         <MCol Cols="12" Md="6" Lg="4">
             <CnGalWebSite.Components.Images.UploadButton @bind-ImagePath="@Model.BackgroundPicture" Type="ImageAspectType.None" Text="上传大背景图" Class="mb-4" />
         </MCol>
         <MCol Cols="12" Md="6" Lg="4">
             <CnGalWebSite.Components.Images.UploadButton @bind-ImagePath="@Model.SmallBackgroundPicture" Type="ImageAspectType.None" Text="上传小背景图" Class="mb-4" />
         </MCol>
         <MCol Cols="12">
         </MCol>
         <MCol Cols="12" Md="6">
             <CnGalWebSite.Components.Inputs.MasaSelecte @bind-Value="Model.Type" TValue="ArticleType" Label="类别" />
         </MCol>
         <CnGalWebSite.Shared.MasaComponent.Shared.Editors.Cards.DisplayNameCard @bind-Name="Model.Name" @bind-DisplayName="Model.DisplayName" Class="form-group col-12 col-sm-6" />

         <MCol Cols="12">
             <MTextarea Rows="3" @bind-Value="Model.BriefIntroduction" Label="简介" />
         </MCol>
         <MCol Cols="12" Md="6">
             <MTextField @bind-Value="Model.OriginalAuthor" Label="原作者" />
         </MCol>
         <MCol Cols="12" Md="6">
             <CnGalWebSite.Components.Inputs.MasaDatePicker @bind-Value="Model.PubishTime" ShowDate ShowTime Nullable="false" Label="发布日期" />
         </MCol>
         <MCol Cols="12" Md="6">
             <MCheckbox @bind-Value="Model.IsCreatedByCurrentUser" Label="本人创作" TValue="bool" />
         </MCol>
         <MCol Cols="12">
             <MTextField @bind-Value="Model.OriginalLink" Label="原文链接" />
         </MCol>
         @if (Model.Type == ArticleType.News)
        {
            <MCol Cols="12">
                <MDivider />
            </MCol>
            <MCol Cols="12" Md="6">
                <MCheckbox @bind-Value="IsSame" Label="动态发生时间与发布日期一致" TValue="bool" />
            </MCol>
            @if (IsSame)
            {
                <MCol Cols="12" Md="6">
                    <CnGalWebSite.Components.Inputs.MasaDatePicker @bind-Value="Model.PubishTime" ShowDate ShowTime Nullable="false" Disabled Label="动态发生时间" />
                 </MCol>
            }
            else
            {
                <MCol Cols="12" Md="6">
                    <CnGalWebSite.Components.Inputs.MasaDatePicker @bind-NullableValue="Model.RealNewsTime" ShowDate ShowTime Nullable Label="动态发生时间" />
                 </MCol>
            }
            <MCol Cols="12" Md="6">
                <MTextField @bind-Value="Model.NewsType" Label="动态类别" />
            </MCol>
        }
    </MRow>

</CnGalWebSite.Components.Containers.MasaTitleContainer>

@code {
    [Parameter]
    public EditArticleMainViewModel Model { get; set; }
    [Parameter]
    public string Class { get; set; }

    private bool IsSame { get; set; }
    protected override void OnInitialized()
    {

        IsSame = Model.PubishTime == Model.RealNewsTime;

        if (Model.RealNewsTime == null)
        {
            IsSame = true;
        }

    }

    public void OnPubishTimeChanged(DateTime time)
    {
        Model.PubishTime = time;

        if (IsSame && Model.Type == ArticleType.News)
        {
            Model.RealNewsTime = time;
        }
    }
}
